Security News
Combatting Alert Fatigue by Prioritizing Malicious Intent
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
original-url
Advanced tools
Reconstruct the original URL used in an HTTP request based on the HTTP request headers
Reconstruct the original URL used in an HTTP request based on the HTTP request headers.
The module takes into account potential URL rewrites made by proxies, load balancers, etc along the way (as long as these append special HTTP headers to the request).
Supported HTTP headers:
Host
Forwarded
X-Forwarded-Proto
X-Forwarded-Protocol
X-Url-Scheme
Front-End-Https
X-Forwarded-Ssl
X-Forwarded-Host
X-Forwarded-Port
If the protocol (http vs https) cannot be determined based on the above
headers, the encrypted
flag on the TLS connection is used.
npm install original-url --save
Server example:
const http = require('http')
const originalUrl = require('original-url')
const server = http.createServer(function (req, res) {
const url = originalUrl(req)
if (url.full) {
res.end(`Original URL: ${url.full}\n`)
} else {
res.end('Original URL could not be determined\n')
}
})
server.listen(1337)
Request examples:
$ curl localhost:1337
Original URL: http://localhost:1337/
$ curl -H 'Host: example.com' localhost:1337
Original URL: http://example.com/
$ curl -H 'Host: example.com:1234' localhost:1337
Original URL: http://example.com:1234/
$ curl -H 'Forwarded: proto=https; host=example.com; for="10.0.0.1:1234"' localhost:1337/sub/path?key=value
Original URL: https://example.com:1234/sub/path?key=value
$ curl -H 'X-Forwarded-Host: example.com' -H 'X-Forwarded-Host: proxy.local' localhost:1337
Original URL: http://example.com/
result = originalUrl(req)
This module exposes a single function which takes an HTTP request object
in the form of
http.IncomingMessage
.
When called, the function returns a result
object with a full
property containing the fully resolved URL. The result
object will
also contain any other property normally returned by the Node.js core
url.parse
function.
If the hostname for some reason cannot be determined, result.full
will
not be present.
FAQs
Reconstruct the original URL used in an HTTP request based on the HTTP request headers
The npm package original-url receives a total of 246,562 weekly downloads. As such, original-url popularity was classified as popular.
We found that original-url demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.
Security News
License exceptions modify the terms of open source licenses, impacting how software can be used, modified, and distributed. Developers should be aware of the legal implications of these exceptions.